package dierweek;

import java.util.Random;
import java.util.Scanner;

public class caishu3 {
    public static void main(String[] args) {
        Random random = new Random();
        int guessnum = random.nextInt(10)+1;
        int flag;
//        System.out.println("guessnum="+guessnum);
        for (flag=0;flag<3;flag++)
        {
            System.out.println("请输入你猜的数字？1-10");
            Scanner scanner = new Scanner(System.in);
            int usernum = scanner.nextInt();
            if (guessnum<usernum){
                System.out.println("猜大了");
            }else if (guessnum>usernum){
                System.out.println("猜小了");
            }else if (guessnum==usernum)
            {
                System.out.println("恭喜你，猜对了！");
                break;
            }
            if (2-flag==0){
                System.out.println("您的机会用完了");
            }else {
                System.out.println("您还剩" + (3 - flag-1) + "次机会");
            }
        }
    }
}

